package com.softstao.guoyu.ui.activity.me;

import android.view.KeyEvent;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;

import com.softstao.guoyu.R;
import com.softstao.guoyu.base.BaseActivity;
import com.softstao.guoyu.global.APIInterface;
import com.softstao.guoyu.global.SharePreferenceManager;
import com.softstao.softstaolibrary.library.widget.ProgressWebView;

import butterknife.BindView;

/**
 * Created by vaikus on 2017/6/23.
 */

public class AuditCertActivity extends BaseActivity {
    @BindView(R.id.web_view)
    ProgressWebView webView;
    private String url;
    private int id;

    @Override
    public int _ContentView() {
        return R.layout.activity_web;
    }

    @Override
    public void initView() {
        initTitle("授权证书");
        id = getIntent().getIntExtra("id",0);
        url = APIInterface.SERVER_WAP + "certificate.html?agentId=" + SharePreferenceManager.getInstance().getAgentId() + "&certId=" + id;
        this.webView.getSettings().setJavaScriptEnabled(true);
        this.webView.addJavascriptInterface(new Object(){
            @JavascriptInterface           // For API 17+
            public void performClick(String strl) {
            }
        },"ok");
        this.webView.getSettings().setDefaultTextEncodingName("UTF-8");
        this.webView.getSettings().setAllowFileAccess(true);
        this.webView.getSettings().setLoadWithOverviewMode(true);
        this.webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == event.KEYCODE_BACK) {//监听返回键，如果可以后退就后退
            if (webView.canGoBack()) {
                webView.goBack();
                return true;

            }
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    protected void onResume() {
        super.onResume();
        webView.loadUrl(url);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        webView.removeAllViews();
        webView.destroy();
    }
}
